/**
 * 
 */
package com.taobao.snowsnow.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.taobao.snowsnow.hibernate.pojo.ExpressPage;

/**
 * @author Administrator
 *
 */
public class Util {
	
	public static final int WAIT_BUYER_PAY = 1;
	public static final int WAIT_SELLER_SEND_GOODS = 2;
	public static final int WAIT_BUYER_CONFIRM_GOODS = 3;
	public static final int SEND_GOODS = 4;
	public static final int PRINT_EXPRESS_LIST = 5;
	
	public static final String DATE_FORMAT_STR = "yyyy-MM-dd HH:mm:ss";
	
	public static int getTradeStringsInt(String status) {
		if(status.equals("WAIT_BUYER_PAY")) {
			return 1;
		} else if(status.equals("WAIT_SELLER_SEND_GOODS")) {
			return 2;
		} else if(status.equals("WAIT_BUYER_CONFIRM_GOODS")) {
			return 3;
		} else if(status.equals("TRADE_FINISHED")) {
			return 4;
		} else if(status.equals("TRADE_CLOSED_BY_TAOBAO")) {
			return 5;
		} else if(status.equals("TRADE_CLOSED")) {
			return 6;
		} else if(status.equals("TRADE_BUYER_SIGNED")) {
			return 7;
		} else if(status.equals("TRADE_NO_CREATE_PAY")) {
			return 8;
		}
		return -1;
	}
	
	/**
	 * <p>转换淘宝API状态成为文字,便于理解
	 * @param status
	 * 			淘宝API的状态,状态为字母表示
	 * @return
	 * 			中文字符表示的状态
	 */
	public static String getTradeStatusStr(int status) {
		switch(status) {
		case 1:
			return "等待买家付款";
		case 2:
			return "等待卖家发货";
		case 3:
			return "等待买家确认";
		case 4:
			return "交易成功";
		case 5:
			return "交易关闭(付款以前，卖家或买家主动关闭交易)";
		case 6:
			return "交易关闭(付款以后用户退款成功，交易自动关闭)";
		case 7:
			return "买家已签收,货到付款专用";
		case 8:
			return "没有创建支付宝交易";
		default:
			return "未知状态";
		}
	}
	
	public static String tradeIntToStr(int status) {
		switch(status) {
		case 1:
			return "WAIT_BUYER_PAY";
		case 2:
			return "WAIT_SELLER_SEND_GOODS";
		case 3:
			return "WAIT_BUYER_CONFIRM_GOODS";
		case 4:
			return "TRADE_FINISHED";
		case 5:
			return "TRADE_CLOSED_BY_TAOBAO";
		case 6:
			return "TRADE_CLOSED";
		case 7:
			return "TRADE_BUYER_SIGNED";
		case 8:
			return "TRADE_NO_CREATE_PAY";
		default:
			return "未知状态";
		}
	}
	
	public static int getFieldPostionX(String position) {
		String[] str = position.split(":");
		return Integer.valueOf(str[0]);
	}
	
	public static int getFieldPostionY(String position) {
		String[] str = position.split(":");
		return Integer.valueOf(str[1]);
	}
	
	public static int getFieldPostionWidth(String position) {
		String[] str = position.split(":");
		return Integer.valueOf(str[2]);
	}
	
	/**
	 * 获取蝴蝶结店铺的模板
	 * @return
	 * 			快递单模板
	 */
	public static ExpressPage getMyleftShopperTemplates() {
		ExpressPage expressPage = new ExpressPage();
		Calendar c = Calendar.getInstance();
		expressPage.setSenderName("安娜");
		expressPage.setOriginCity("柳州");
		expressPage.setSenderCompany("淘宝旺旺ID: myleft1");
		expressPage.setSenderAddress1("http://snowsnow.taobao.com");
		expressPage.setSenderAddress2("雪雪原创 蝴蝶结专卖店 婚纱礼服蝴蝶结定制");
		expressPage.setSenderPhone("0772-2818316");
		expressPage.setYear(String.valueOf(c.get(Calendar.YEAR)));
		expressPage.setMonth(String.valueOf(c.get(Calendar.MONTH) + 1));
		expressPage.setDay(String.valueOf(c.get(Calendar.DAY_OF_MONTH)));
		expressPage.setSellGoodsName("蝴蝶结");
		expressPage.setSenderSign("安娜");
		
		return expressPage;
	}
	
	/**
	 * 获取当前时间
	 * @return
	 *			当前时间
	 */
	public static Date getDateTime() {
		Calendar c = Calendar.getInstance();
		return c.getTime();
	}
	
	/**
	 * 获取年月日
	 * @return
	 */
	public static Date getDate() {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		return c.getTime();
	}
	
	public static String dateToString(Date d) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(d);
	}
}
